package HashTable;

public class _463_IslandPerimeter {
    public int islandPerimeter(int[][] grid) {
        int counts = 0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if (grid[i][j] == 1) {
                    if (i - 1 < 0) {
                        counts++;
                    } else if (grid[i - 1][j] == 0) {
                        counts++;
                    }
                    if (i + 1 >= grid.length) {
                        counts++;
                    } else if (grid[i + 1][j] == 0) {
                        counts++;
                    }
                    if (j - 1 < 0) {
                        counts++;
                    } else if (grid[i][j - 1] == 0) {
                        counts++;
                    }
                    if (j + 1 >= grid[0].length) {
                        counts++;
                    } else if (grid[i][j + 1] == 0) {
                        counts++;
                    }
                }
            }
        }
        return counts;
    }
}
